package com.nisco.dms.service;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.google.common.collect.Maps;
import com.nisco.dms.entity.Tbmb;
import com.nisco.dms.repository.mybatis.TbmbMyBatisDao;

/**
 * 
 * @author joey
 * 
 */
@Component
@Transactional(readOnly = true)
public class TbmbService {
	@Autowired
	private TbmbMyBatisDao tbmbMyBatisDao;

	/**
	 * 获取所有数据
	 * @return
	 */
	public List<Tbmb> getAll() {
		return tbmbMyBatisDao.getAll();
	}
	
	/**
	 * 分页查询
	 * @param pageNow
	 * @param pageSize
	 * @return
	 */
	public List<Tbmb> getAllByPage(int pageNow,int pageSize) {
		Map<String, Object> parameters = Maps.newHashMap();
		parameters.put("start", pageNow);
		parameters.put("end", pageSize);
		return tbmbMyBatisDao.getAllByPage(parameters);
	}
	
	/**
	 * 根据姓名、性别查询
	 * @param name
	 * @param sex
	 * @return
	 */
	public List<Tbmb> search(String name, String sex) {
		Map<String, Object> parameters = Maps.newHashMap();
		if (name == null || name == "") {
			parameters.put("name", name);
			parameters.put("sex", null);
		} else if (sex == null || sex == "") {
			parameters.put("name", null);
			parameters.put("sex", sex);
		} else {
			parameters.put("name", name);
			parameters.put("sex", sex);
		}

		return tbmbMyBatisDao.search(parameters);
	}

	/**
	 * 查询
	 * @param param
	 * @return
	 */
	public List<Tbmb> search(String param) {
		Map<String, Object> parameters = Maps.newHashMap();
		parameters.put("name", param);
		parameters.put("sex", param);
		parameters.put("age", param);
		return tbmbMyBatisDao.search(parameters);
	}
	
	/**
	 * 分页查询
	 * @param param
	 * @param pageNow
	 * @param pageSize
	 * @return
	 */
	public List<Tbmb> search(String param,int pageNow,int pageSize) {
		Map<String, Object> parameters = Maps.newHashMap();
		parameters.put("name", param);
		parameters.put("sex", param);
		parameters.put("age", param);
		parameters.put("start", pageNow);
		parameters.put("end", pageSize);
		return tbmbMyBatisDao.searchByPage(parameters);
	}

	/**
	 * 根据id查询
	 * @param id
	 * @return
	 */
	public Tbmb get(String id) {
		return tbmbMyBatisDao.get(id);
	}

	/**
	 * 保存
	 * @param tbmb
	 */
	@Transactional
	public void save(Tbmb tbmb) {
		tbmbMyBatisDao.save(tbmb);
	}

	/**
	 * 删除
	 * @param id
	 */
	@Transactional
	public void delete(String id) {
		tbmbMyBatisDao.delete(id);
	}

	/**
	 * 修改
	 * @param tbmb
	 */
	@Transactional
	public void update(Tbmb tbmb) {
		tbmbMyBatisDao.update(tbmb);
	}
}
